package com.company.poker.protocol;

import java.io.Serializable;

/**
 * Description of class.
 * Created 4/12/13 5:45 PM
 *
 * @author andrey.rodin@playtech.com
 */

public final class ByteMessage implements Serializable {
    private static final long serialVersionUID = 7750314382564661583L;
    private final Header header;
    private final String body;

    public ByteMessage(Header header, String body) {
        this.header = header;
        this.body = body;
    }

    public Header getHeader() {
        return header;
    }

    public String getBody() {
        return body;
    }

    public static ByteMessage byteToMessage(byte[] bytes) {
        return null;
    }

    public static byte[] messageToByte(ByteMessage msg) {
        return new byte[0];
    }

    public static HeaderBuilder newHeaderBuilder() {
        return new HeaderBuilder();
    }

    public static final class HeaderBuilder {
        private AddresseeType from;
        private AddresseeType to;
        private ProtocolType protocolType;
        private MessageType messageType;
        private String userToken;
        private String addressId;

        public HeaderBuilder setFrom(AddresseeType from) {
            this.from = from;
            return this;
        }

        public HeaderBuilder setTo(AddresseeType to) {
            this.to = to;
            return this;
        }

        public HeaderBuilder setProtocolType(ProtocolType protocolType) {
            this.protocolType = protocolType;
            return this;
        }

        public HeaderBuilder setMessageType(MessageType messageType) {
            this.messageType = messageType;
            return this;
        }

        public HeaderBuilder setUserToken(String userToken) {
            this.userToken = userToken;
            return this;
        }

        public HeaderBuilder setAddressId(String addressId) {
            this.addressId = addressId;
            return this;
        }

        public Header build() {
            return new Header(from, to, protocolType,
                     messageType, userToken, addressId);
        }
    }

    public static final class Header {
        private final AddresseeType from;
        private final AddresseeType to;
        private final ProtocolType protocolType;
        private final MessageType messageType;
        private final String userToken;
        private final String addressId;

        public Header(AddresseeType from, AddresseeType to, ProtocolType protocolType,
                      MessageType messageType, String userToken, String addressId) {
            this.from = from;
            this.to = to;
            this.protocolType = protocolType;
            this.messageType = messageType;
            this.userToken = userToken;
            this.addressId = addressId;
        }

        public AddresseeType getFrom() {
            return from;
        }

        public AddresseeType getTo() {
            return to;
        }

        public ProtocolType getProtocolType() {
            return protocolType;
        }

        public MessageType getMessageType() {
            return messageType;
        }

        public String getUserToken() {
            return userToken;
        }

        public String getAddressId() {
            return addressId;
        }
    }
}
